package listen;

import java.io.FileWriter;
import java.io.PrintWriter;
import java.util.Date;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

import com.sun.glass.ui.Timer;
import com.sun.javafx.tk.Toolkit.Task;

public class LogListener implements ServletContextListener {
	Timer timer = null;
	MyTask Task = null;
	Date begin = null;
	@Override
	public void contextDestroyed(ServletContextEvent arg0) {
		// TODO 自动生成的方法存根
		System.out.println("WEB应用即将关闭...");
		try {
			//FileOutputStream file = new FileOutputStream("K:\\mylog.txt");
		//	OutputStreamWriter out = new OutputStreamWriter(file);
			FileWriter file1 = new FileWriter("K:\\javaeeLog\\mylog.txt", true);
			PrintWriter out1 = new PrintWriter(file1);
			out1.write("启动时间" + begin + "\r\n");
			out1.write("结束时间" + new Date() + "\r\n");
			out1.close();
		}
		catch (Exception e) {
			System.out.println(e);
		}
	}

	@Override
	public void contextInitialized(ServletContextEvent arg0) {
		System.out.println("WEB应用初始开始...");
		begin = new Date();
		System.out.println(begin.toString());
	}

}
